<?php
class Select extends FormElement {
	
	private $optionArray = array();
	
	public function __construct($elementId, $labelText) {
	
		parent::__construct($elementId, $labelText);
	}
	
	public function addOption($value, $text = NULL) {
		
		if ($text == NULL) {
			$text = $value;
		}
		
		$this->optionArray[$value] = $text;
	}
	
	protected function renderElement() {
		
		$hiddenLabelClass = '';
		if ($this->labelVisibility == Label::$labelHidden) {
			$hiddenLabelClass = 'class="ui-hidden-accessible"';
		}
	
		echo '<label for="', $this->elementId, '" ', $hiddenLabelClass, ' >', $this->labelText, '</label>';
		echo '<select name="', $this->elementId, '" ', $this->formatAttributes(), '>';
		
		foreach ($this->optionArray as $value => $text) {
			
			$selected = '';
			
			if (strcmp($this->getDefaultValue(), $value) == 0) {
				$selected = 'selected="selected"';
			}
			
			echo '<option value="', $value, '" ', $selected, ' >', $text, '</option>';
		}
		
		echo '</select>';
	}
}
?>